<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <!--    <div class="table-operator">-->
    <!--      <a-button @click="handleAdd" type="primary" icon="plus" :hidden="disabled" :disabled="isDisabledAuth('erpAuditLitigation:add')">新增</a-button>-->
    <!--    </div>-->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:'100%'}"
        bordered
        rowKey="id"
        :columns="defColumns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            @click="handleEdit(record)"
            :hidden="disabled"
            :disabled="isDisabledAuth('erpAuditLitigation:edit')"
          />
        </span>
      </a-table>
    </div>
    <erp-audit-manage-clearing-dt-modal ref="modalForm" @dataOne="dataOne" @ok="modalFormOk"></erp-audit-manage-clearing-dt-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpAuditManageClearingDtModal from './modules/ErpAuditManageClearingDtModal'
  import { getAction } from '@/api/manage'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'

  export default {
    name: 'ErpAuditManageClearingDtList',
    mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpAuditManageClearingDtModal,
      ErpProjectReportModal
    },
    props: {
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
        queryParam: {
          mainId: null
        },
        /* 数据源 */
        dataSource: [],
        /* 分页参数 */
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        /* 排序参数 */
        isorter: {
          column: 'createTime',
          order: 'desc'
        },
        /* 筛选参数 */
        filters: {},
        /* table加载状态 */
        loading: false,
        /* table选中keys */
        selectedRowKeys: [],
        /* table选中records */
        selectionRows: [],
        /* 查询折叠 */
        toggleSearchStatus: false,
        /* 高级查询条件生效状态 */
        superQueryFlag: false,
        /* 高级查询条件 */
        superQueryParams: '',
        /** 高级查询拼接方式 */
        superQueryMatchType: 'and',
        iconStyle: { 'font-size': '18px', 'cursor': 'pointer' },
        colsettings: ':colsettings',

        description: '讼申请单明细管理页面',
        // 表头
        columns: [],
        // 列设置
        settingColumns: [],
        // 列定义
        defColumns: [
          {
            title: '款项名称',
            align: 'center',
            dataIndex: 'paymentNodeName',
            ellipsis: true
          },
          {
            title: '应收款金额(元)',
            align: 'center',
            dataIndex: 'paymentMoney',
            ellipsis: true
          },
          {
            title: '实收金额(元)',
            align: 'center',
            dataIndex: 'realCollectionPaymentMoney',
            ellipsis: true
          },
          {
            title: '管理费(元)',
            align: 'center',
            dataIndex: 'manageMoney',
            ellipsis: true
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
            ellipsis: true
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          // 查询子表
          list: '/api/erp/audit/manage/erpAuditManageClearingDetail/list'
        },
        dictOptions: {},
        superFieldList: []
      }
    },
    created() {
      // 加载数据字典信息
      this.initDictConfig();
      if (this.disabled) {
        this.defColumns.pop()
      }
    },
    computed: {
    },
    methods: {
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams() // 查询条件
        this.loading = true
        getAction(this.url.list, params).then(res => {
          if (res.success) {
            // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = []
            let dataSource = res.result.records || res.result
            dataSource.forEach(data => {
              this.dataOne(data, true)
            })
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            // 判断是否当前页没有数据且不为第一页
            if (this.dataSource.length == 0 && this.ipagination.current != 1) {
              this.ipagination.current = this.ipagination.current - 1
              this.loadData(this.ipagination.current - 1);
            }
            // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.dataSource = [];
            this.ipagination.total = 0
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      initDictConfig() {
      },
      handleTableChange() {
        // 更新dataSource
        this.dataSource.forEach((item, index) => {
          item.key = index
        })
      },
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record)
        console.log('编辑：', this.dataSource)
        this.$refs.modalForm.title = '编辑'
        this.$refs.modalForm.disableSubmit = false
      },
      handleAdd: function () {
        this.$refs.modalForm.add()
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
      },
      modalFormOk(data) {

      },
      dataOne(data, flag) {
        console.log('dataOne', data, flag)
        if (flag) {
          this.dataSource.push(data)
          this.dataSource.forEach((item, index) => {
            item.key = index
          })
        } else {
          this.dataSource.splice(data.key, 1, data);
        }
      },
      submitForm() {
        return this.dataSource
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
